package com.lineage;

import com.add.L1PcUnlock;
import com.lineage.server.datatables.lock.CharSkillReading;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Teleport;
import com.lineage.server.serverpackets.S_NPCTalkReturn;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.S_SystemMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.utils.FaceToFace;
import java.util.logging.Logger;

public class FollowAutoAttackUpdate {
  private static Logger _log = Logger.getLogger(FollowAutoAttackUpdate.class.getName());
  
  private static FollowAutoAttackUpdate _instance;
  
  public static FollowAutoAttackUpdate getInstance() {
    if (_instance == null)
      _instance = new FollowAutoAttackUpdate(); 
    return _instance;
  }
  
  public boolean PcCommand(L1PcInstance _pc, String cmd) {
    if (cmd.equalsIgnoreCase("followatk")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("您不是高宠状态无法设定。"));
        return false;
      } 
      if (_pc.getfollowatk()) {
        _pc.setfollowatk(false);
        if (_pc.isActived()) {
          _pc.setActived(false);
          L1PcUnlock.Pc_Unlock(_pc);
          if (_pc.get_fwgj() > 0) {
            _pc.setlslocx(0);
            _pc.setlslocy(0);
            _pc.set_fwgj(0);
          } 
          _pc.killSkillEffectTimer(8853);
        } 
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("高宠自动打怪：关闭"));
      } else {
        _pc.setfollowatk(true);
        if (!_pc.isActived())
          _pc.startAI(); 
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("高宠自动打怪：开启"));
      } 
    } else if (cmd.equalsIgnoreCase("followatkmagic")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("您不是高宠状态无法设定。"));
        return false;
      } 
      if (_pc.getfollowatkmagic()) {
        _pc.setfollowatkmagic(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("高宠自动打怪施放攻击魔法：关闭"));
      } else {
        _pc.setfollowatkmagic(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("高宠自动打怪施放攻击魔法：开启"));
      } 
    } else if (cmd.equals("followmecheck")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (_pc.isfollowcheck()) {
        _pc.setfollowcheck(false);
        _pc.set_followmaster(null);
        _pc.setfollow(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("[关闭]禁止高宠跟随状态"));
        L1PcUnlock.Pc_Unlock(_pc);
        followpc(_pc);
      } else {
        _pc.setfollowcheck(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("[开启]允许高宠跟随状态"));
        followpc(_pc);
      } 
    } else if (cmd.equals("followme")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      L1PcInstance target = FaceToFace.faceToFace(_pc);
      if (target != null) {
        if (!target.isfollowcheck()) {
          _pc.sendPackets((ServerBasePacket)new S_ServerMessage("高宠对象目前关闭跟随状态中。"));
          return false;
        } 
        if (!_pc.isfollowcheck()) {
          _pc.sendPackets((ServerBasePacket)new S_ServerMessage("您目前关闭高宠状态,请先开启。"));
          return false;
        } 
        if (target.get_followmaster() != null) {
          _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你指定的对象已有追随者。"));
          return false;
        } 
        if (_pc.get_followmaster() != null) {
          _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你已有追随者。"));
          return false;
        } 
        if (target.isfollow()) {
          _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你指定的对象已有追随者。"));
          return false;
        } 
        if (_pc.isfollow()) {
          _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你已有追随者,请重新关闭再开启。"));
          return false;
        } 
        _pc.set_followmaster(target);
        target.setfollow(true);
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("您成为:[" + target.getName() + "]高宠补助"));
        target.sendPackets((ServerBasePacket)new S_ServerMessage("[" + _pc.getName() + " ]成为您的高宠补助"));
      } 
    } else if (cmd.equals("followmeclose")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (_pc.hasSkillEffect(95414))
        return false; 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未有跟随主人对象"));
        return false;
      } 
      _pc.setSkillEffect(95414, 10000);
      _pc.set_followmaster(null);
      _pc.set_followstep(0);
      _pc.setfollow(false);
      L1PcUnlock.Pc_Unlock(_pc);
      L1Teleport.teleport(_pc, _pc.getLocation(), _pc.getHeading(), false);
      _pc.sendPackets((ServerBasePacket)new S_SystemMessage("[关闭]高宠跟随辅助"));
    } else if (cmd.equals("followmeskill")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.getfollowskilltype() == 0) {
        _pc.setfollowskilltype(1);
      } else if (_pc.getfollowskilltype() == 1) {
        _pc.setfollowskilltype(2);
      } else if (_pc.getfollowskilltype() == 2) {
        _pc.setfollowskilltype(3);
      } else if (_pc.getfollowskilltype() == 3) {
        _pc.setfollowskilltype(4);
      } else if (_pc.getfollowskilltype() == 4) {
        _pc.setfollowskilltype(0);
      } 
      if (_pc.getfollowskilltype() == 1 && !CharSkillReading.get().spellCheck(_pc.getId(), 1)) {
        _pc.setfollowskilltype(0);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习治愈术"));
        followpc(_pc);
      } 
      if (_pc.getfollowskilltype() == 2 && !CharSkillReading.get().spellCheck(_pc.getId(), 19)) {
        _pc.setfollowskilltype(0);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习治愈术"));
        followpc(_pc);
      } 
      if (_pc.getfollowskilltype() == 3 && !CharSkillReading.get().spellCheck(_pc.getId(), 35)) {
        _pc.setfollowskilltype(0);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习治愈术"));
        followpc(_pc);
      } 
      if (_pc.getfollowskilltype() == 4 && !CharSkillReading.get().spellCheck(_pc.getId(), 164)) {
        _pc.setfollowskilltype(0);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习治愈术"));
        followpc(_pc);
      } 
      followpc(_pc);
    } else if (cmd.equals("followmeHp1")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.getfollowskillhp() >= 100)
        return false; 
      _pc.setfollowskillhp(_pc.getfollowskillhp() + 5);
      followpc(_pc);
    } else if (cmd.equals("followmeHp2")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.getfollowskillhp() == 0)
        return false; 
      _pc.setfollowskillhp(_pc.getfollowskillhp() - 5);
      followpc(_pc);
    } else if (cmd.equalsIgnoreCase("skill1")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 26)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习体魄术"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.isfollowskill26()) {
        _pc.setfollowskill26(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:体魄术"));
        followpc(_pc);
      } else {
        _pc.setfollowskill26(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:体魄术"));
        followpc(_pc);
      } 
    } else if (cmd.equalsIgnoreCase("skill2")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 42)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习通畅术"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.isfollowskill42()) {
        _pc.setfollowskill42(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:通畅术"));
        followpc(_pc);
      } else {
        _pc.setfollowskill42(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:通畅术"));
        followpc(_pc);
      } 
    } else if (cmd.equalsIgnoreCase("skill3")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 55)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习狂暴术"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (!_pc.isWizard()) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您不是法师,无法开启狂暴术"));
        return false;
      } 
      if (_pc.isfollowskill55()) {
        _pc.setfollowskill55(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:狂暴术"));
        followpc(_pc);
      } else {
        _pc.setfollowskill55(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:狂暴术"));
        followpc(_pc);
      } 
    } else if (cmd.equalsIgnoreCase("skill4")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 68)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习圣结界"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.isfollowskill68()) {
        _pc.setfollowskill68(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:圣结界"));
        followpc(_pc);
      } else {
        _pc.setfollowskill68(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:圣结界"));
        followpc(_pc);
      } 
    } else if (cmd.equalsIgnoreCase("skill6")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 79)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习灵魂升华"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (!_pc.isWizard()) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您不是法师,无法开启灵魂升华"));
        return false;
      } 
      if (_pc.isfollowskill79()) {
        _pc.setfollowskill79(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:灵魂升华"));
        followpc(_pc);
      } else {
        _pc.setfollowskill79(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:灵魂升华"));
        followpc(_pc);
      } 
    } else if (cmd.equalsIgnoreCase("skill7")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 148)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习火焰武器"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.isfollowskill148()) {
        _pc.setfollowskill148(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:火焰武器"));
        followpc(_pc);
      } else {
        _pc.setfollowskill148(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:火焰武器"));
        followpc(_pc);
      } 
    } else if (cmd.equalsIgnoreCase("skill8")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 151)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习大地防护"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.isfollowskill151()) {
        _pc.setfollowskill151(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:大地防护"));
        followpc(_pc);
      } else {
        _pc.setfollowskill151(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:大地防护"));
        followpc(_pc);
      } 
    } else if (cmd.equalsIgnoreCase("skill9")) {
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 149)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习风之神射"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.isfollowskill149()) {
        _pc.setfollowskill149(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:风之神射"));
        followpc(_pc);
      } else {
        _pc.setfollowskill149(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:风之神射"));
        followpc(_pc);
      } 
    } else {
      if (!cmd.equalsIgnoreCase("skill10"))
        return false; 
      L1ItemInstance AiITEM = _pc.getInventory().findItemId(95182);
      if (AiITEM == null) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("休想窜改对话档,我已经纪录你了。"));
        return false;
      } 
      if (!CharSkillReading.get().spellCheck(_pc.getId(), 158)) {
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("您尚未学习生命之泉"));
        return false;
      } 
      if (_pc.get_followmaster() == null) {
        _pc.sendPackets((ServerBasePacket)new S_ServerMessage("你不是高宠无法使用此功能。"));
        return false;
      } 
      if (_pc.isfollowskill158()) {
        _pc.setfollowskill158(false);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("关闭自动补助技能:生命之泉"));
        followpc(_pc);
      } else {
        _pc.setfollowskill158(true);
        _pc.sendPackets((ServerBasePacket)new S_SystemMessage("开启自动补助技能:生命之泉"));
        followpc(_pc);
      } 
    } 
    return true;
  }
  
  public void followpc(L1PcInstance _pc) {
    try {
      int i = 0;
      String type1 = "尚未设置";
      String type2 = "0";
      String type3 = "禁止跟随";
      String type4 = "关闭";
      String type5 = "关闭";
      String type6 = "关闭";
      String type7 = "关闭";
      String type8 = "关闭";
      String type9 = "关闭";
      String type10 = "关闭";
      String type11 = "关闭";
      String type12 = "关闭";
      String type13 = "关闭";
      if (_pc.getfollowskilltype() == 0) {
        type1 = "尚未设置";
      } else if (_pc.getfollowskilltype() == 1) {
        type1 = "初级治愈术";
      } else if (_pc.getfollowskilltype() == 2) {
        type1 = "中级治愈术";
      } else if (_pc.getfollowskilltype() == 3) {
        type1 = "高级治愈术";
      } else if (_pc.getfollowskilltype() == 4) {
        type1 = "生命的祝福";
      } 
      if (_pc.getfollowskillhp() > 0)
        i = _pc.getfollowskillhp(); 
      if (_pc.isfollowcheck())
        type3 = "允许跟随"; 
      if (_pc.isfollowskill26())
        type4 = "开启"; 
      if (_pc.isfollowskill42())
        type5 = "开启"; 
      if (_pc.isfollowskill55())
        type6 = "开启"; 
      if (_pc.isfollowskill68())
        type7 = "开启"; 
      if (_pc.isfollowskill79())
        type8 = "开启"; 
      if (_pc.isfollowskill148())
        type9 = "开启"; 
      if (_pc.isfollowskill151())
        type10 = "开启"; 
      if (_pc.isfollowskill149())
        type11 = "开启"; 
      if (_pc.isfollowskill158())
        type12 = "开启"; 
      _pc.sendPackets((ServerBasePacket)new S_NPCTalkReturn(_pc.getId(), "Lh8", new String[] { 
              type1, i+"", type3, type4, type5, 
              type6, type7, type8, type9, type10, 
              type11, type12, "关闭" }));
    } catch (Exception exception) {}
  }
}
